<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>

</html>
<?php
//Connect to database
$conn = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db("mydb", $conn) or die(mysql_error());

//Intiating per page to 5 conferences per page
if ($_GET['pp'] > 0 || $_GET['pp'] == Null) {
    $pp = ( isset($_GET['pp']) ) ? (int) $_GET[pp] : 5;
} else {
    echo '<script type="text/javascript">', 'alert("Error: You can not set the view per page to this value!")', '</script>';
    $pp = 5;
}

//Calculating the total number of pages needed to view the information
$result = mysql_query("SELECT conference_id FROM conference") Or die(mysql_error());
$users_nm = mysql_num_rows($result);
$total_pages = (int) ceil($users_nm / $pp);

//Intiating the initial page and handling inputs exceptions
if ($_GET['p'] <= $total_pages && $_GET['p'] > 0 || $_GET['p'] == Null) {
    $p = ( isset($_GET['p']) ) ? (int) $_GET[p] : 1;
} else {
    if ($_GET['p'] <= 0 && $_GET['p'] != null) {
        $p = 1;
        echo '<script type="text/javascript">', 'alert("Error: You Can Not Jump to the Specified Page")', '</script>';
    } else {
        $p = $total_pages;
        echo '<script type="text/javascript">', 'alert("Error: You Can Not Jump to the Specified Page")', '</script>';
    }
}
$start = (int) ( $p - 1 ) * $pp;
$result = mysql_query("SELECT conference_id, long_name FROM conference LIMIT $start, $pp") Or die(mysql_error());
echo '<table width="100%">
<tr>
<td><b>Conference</b>
</td>
</tr>';
while ($row = mysql_fetch_assoc($result)) {
    echo "<tr>
<td>{$row['long_name']}</td>
<td><a href='conferencePage.php?conference_id={$row['conference_id']}'>Go To Conference</a </td>
</tr>";
}
echo '</table>';
if ($total_pages > 1 && $p <= $total_pages) {
    for ($x = 1; $x <= $total_pages && $x <= 6; $x++) {
        echo '<a href="?p=' . $x . '&pp=' . $pp . '">' . $x . '</a> ';
    }
}
?>
<html>
    <head>
        <link href="style3.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div id="Status">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p><strong>You are currently viewing page <?PHP echo $p ?> of <?PHP echo $total_pages ?> and viewing <?PHP echo $pp ?> conference(s) per page</strong></p>
            </form>
        </div>
        <div id="SetPerPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="SetPerPage" enctype="multipart/form-data">
                <p>Display#:
                    <input name="pp" value="<?php print $pp; ?>"size="5" maxlength="100">
                </p>
                <p>
                    <input name="Set" type="submit" value="Set">
                </p>
            </form>
        </div>
        <div id="JumpToPage">
            <form action= 'ViewConferencesPerPage.php' method="GET" name="JumpToPage" enctype="multipart/form-data">
                <p>Jump to page:
                    <input name="p" value="<?php print $p; ?>" size="5" maxlength="100">
                </p>
                <p>
                    <input name="Go" type="submit" value="Go">
                </p>
                <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
            </form>
        </div>
        <?php if ($p < $total_pages): ?>
            <div id="Next">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="Next" enctype="multipart/form-data">
                    <p>
                        <input name="Next" type="submit" value="Next Page">
                    </p>
                    <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
                    <input name="p" type="hidden"  value="<?php echo $p + 1; ?>">
                </form>
            </div>
        <?php else: ?>
            <div id="NextInactive">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="NextInactive" enctype="multipart/form-data" disabled="disabled">
                    <p>
                        <input name="NextInactive" type="submit" value="Next Page" disabled="disabled">
                    </p>
                    <input name="pp" type="hidden"  value=" <?php echo $pp; ?> ">
                    <input name="p" type="hidden"  value=" <?php echo $p + 1; ?>">
                <?php endif; ?>
            </form>
        </div>

        <?php if ($p == 1): ?>
            <div id="PreviousInactive">
                <form action= 'ViewConferencesPerPage.php' method="GET" name="PreviousInactive" enctype="multipart/form-data" disabled="disabled">
                    <p>
                        <input name="PreviousInactive" type="submit" value="Previous Page" disabled="disabled">
                    </p>
                    <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
                    <input name="p" type="hidden"  value="<?php echo $p - 1; ?>">
                </form>
            </div>
        </body>
    </html>
<?php else: ?>
    <div id="Previous">
        <form action= 'ViewConferencesPerPage.php' method="GET" name="ViewConferences" enctype="multipart/form-data">
            <p>
                <input name="Next" type="submit" value="Previous Page">
            </p>
            <input name="pp" type="hidden"  value="<?php echo $pp; ?>">
            <input name="p" type="hidden"  value="<?php echo $p - 1; ?>">
        </form>
    </div>
<?php endif; ?>
</body>
</html>